{% extends "base.html" %}

{% block title %}设计案例 - {{ super() }}{% endblock %}

{% block content %}
<div class="container">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h1>设计案例</h1>
        {% if current_user.is_authenticated %}
        <a href="{{ url_for('design.create') }}" class="btn btn-primary">
            <i class="fas fa-plus"></i> 发布案例
        </a>
        {% endif %}
    </div>

    <!-- 筛选器 -->
    <div class="card mb-4">
        <div class="card-body">
            <form method="get" class="row g-3">
                <div class="col-md-4">
                    <input type="text" class="form-control" name="keyword" placeholder="搜索案例..." value="{{ request.args.get('keyword', '') }}">
                </div>
                <div class="col-md-3">
                    <select class="form-select" name="category">
                        <option value="">所有分类</option>
                        <option value="居住区景观" {% if request.args.get('category') == '居住区景观' %}selected{% endif %}>居住区景观</option>
                        <option value="公园设计" {% if request.args.get('category') == '公园设计' %}selected{% endif %}>公园设计</option>
                        <option value="商业景观" {% if request.args.get('category') == '商业景观' %}selected{% endif %}>商业景观</option>
                        <option value="校园景观" {% if request.args.get('category') == '校园景观' %}selected{% endif %}>校园景观</option>
                    </select>
                </div>
                <div class="col-md-3">
                    <select class="form-select" name="sort">
                        <option value="newest" {% if request.args.get('sort') == 'newest' %}selected{% endif %}>最新发布</option>
                        <option value="popular" {% if request.args.get('sort') == 'popular' %}selected{% endif %}>最受欢迎</option>
                        <option value="views" {% if request.args.get('sort') == 'views' %}selected{% endif %}>最多浏览</option>
                    </select>
                </div>
                <div class="col-md-2">
                    <button type="submit" class="btn btn-primary w-100">筛选</button>
                </div>
            </form>
        </div>
    </div>

    <!-- 案例列表 -->
    <div class="row g-4">
        {% for design in designs.items %}
        <div class="col-md-4">
            <div class="card h-100">
                <img src="{{ design.cover_image or url_for('static', filename='images/default-design.jpg') }}" 
                     class="card-img-top" alt="{{ design.title }}" style="height: 200px; object-fit: cover;">
                <div class="card-body">
                    <h5 class="card-title">{{ design.title }}</h5>
                    <p class="card-text text-muted">{{ design.description[:100] }}...</p>
                    <div class="d-flex justify-content-between align-items-center">
                        <div class="btn-group">
                            <a href="{{ url_for('design.detail', id=design.id) }}" class="btn btn-sm btn-outline-primary">查看详情</a>
                            {% if current_user.is_authenticated and current_user.id == design.user_id %}
                            <a href="{{ url_for('design.edit', id=design.id) }}" class="btn btn-sm btn-outline-secondary">编辑</a>
                            {% endif %}
                        </div>
                        <small class="text-muted">
                            <i class="fas fa-eye"></i> {{ design.views }}
                            <i class="fas fa-heart ms-2"></i> {{ design.likes }}
                        </small>
                    </div>
                </div>
                <div class="card-footer">
                    <small class="text-muted">
                        <i class="fas fa-user"></i> {{ design.user.username }}
                        <span class="ms-2"><i class="fas fa-clock"></i> {{ design.created_at.strftime('%Y-%m-%d') }}</span>
                    </small>
                </div>
            </div>
        </div>
        {% endfor %}
    </div>

    <!-- 分页 -->
    {% if designs.pages > 1 %}
    <nav aria-label="Page navigation" class="mt-4">
        <ul class="pagination justify-content-center">
            {% for page_num in designs.iter_pages() %}
                {% if page_num %}
                    {% set args = request.args.copy() %}
                    {% set _ = args.pop('page', None) %}
                    <li class="page-item {% if page_num == designs.page %}active{% endif %}">
                        <a class="page-link" href="{{ url_for('design.index', page=page_num, **args) }}">{{ page_num }}</a>
                    </li>
                {% else %}
                    <li class="page-item disabled"><span class="page-link">...</span></li>
                {% endif %}
            {% endfor %}
        </ul>
    </nav>
    {% endif %}
</div>
{% endblock %} 